package com.example.neusoft215gdh.androidpro_21.Fragement;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.neusoft215gdh.androidpro_21.Activity.SearchClubActivity;
import com.example.neusoft215gdh.androidpro_21.Adapter.ClubAdapter;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubCourse;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubDetail;
import com.example.neusoft215gdh.androidpro_21.JavaBean.ClubList;
import com.example.neusoft215gdh.androidpro_21.Listener.ClubListener;
import com.example.neusoft215gdh.androidpro_21.Model.ClubModel;
import com.example.neusoft215gdh.androidpro_21.R;

import java.util.List;

import static com.example.neusoft215gdh.androidpro_21.R.id.renqi;
import static com.example.neusoft215gdh.androidpro_21.R.id.zuijin;
public class ClubFragment extends Fragment implements ClubListener,View.OnClickListener
{
	private RecyclerView recyclerView;
	private Button renqi1;
	private Button zuijin1;
	List<ClubList> list;
	ImageView search_club;
    String userid;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
	{
		//把.java文件和club_fragment文件关联
	View view=inflater.inflate(R.layout.club_fragment, container, false);
		initRecyclerView(view);
		renqi1.setOnClickListener(this);
		zuijin1.setOnClickListener(this);
		search_club.setOnClickListener(this);
		//联网4步
		ClubModel clubModel=new ClubModel();
		clubModel.getClubMaxRe(userid,1,this);
		return view;
	}
	public  void initRecyclerView(View view){
		recyclerView= (RecyclerView) view.findViewById(R.id.re_club);
		recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
		recyclerView.setItemAnimator(new DefaultItemAnimator());
		renqi1= (Button) view.findViewById(R.id.renqi);
		zuijin1= (Button) view.findViewById(R.id.zuijin);
		search_club= (ImageView) view.findViewById(R.id.search_club);
	}

	@Override
	public void onResponse(List<ClubList> bean) {
         list=bean;
		recyclerView.setAdapter(new ClubAdapter(getActivity(),list));
	}

	@Override
	public void onResponseClubDetailVideo(List<ClubDetail> bean) {

	}

	@Override
	public void onResponseClubDetailjianjie(ClubDetail bean) {

	}

	@Override
	public void onResponseClubDetailCourse(ClubCourse bean) {

	}



	@Override
	public void onFail(String msg) {
		Toast.makeText(getActivity(), ""+msg, Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onClick(View v) {
		SharedPreferences  user=getActivity().getSharedPreferences("Userid",0);
		userid=user.getString("user_id","");
		switch (v.getId()){
			case renqi:
				renqi1.setBackgroundResource(R.drawable.text_border);
				zuijin1.setBackgroundColor(Color.parseColor("#ffffff"));
				renqi1.setTextColor(Color.parseColor("#66CD00"));
				zuijin1.setTextColor(Color.parseColor("#ADADAD"));
				ClubModel clubModel=new ClubModel();
				clubModel.getClubMaxRe(userid,1,this);
				break;
			case zuijin:

				zuijin1.setBackgroundResource(R.drawable.text_border);
				renqi1.setBackgroundColor(Color.parseColor("#ffffff"));
				zuijin1.setTextColor(Color.parseColor("#66CD00"));
				renqi1.setTextColor(Color.parseColor("#ADADAD"));
				ClubModel clubModel1=new ClubModel();
				clubModel1.getClubZuiJin(userid,45,45,1,this);
				break;
			case R.id.search_club:
				Intent intent2=new Intent(getActivity(),SearchClubActivity.class);
				startActivity(intent2);
		}
	}
}
